/*
 * @Author: xuchao 
 * @Date: 2018-05-14 16:58:01 
 * @Last Modified by: xuchao
 * @Last Modified time: 2018-06-26 15:14:01
 * 
 * Home: 前台 router
 * Management: 管理后台 router
 */
import React, { Component } from 'react';
import { Switch, Route, Redirect, withRouter } from 'react-router-dom';

/* homme */
import Login from '@/views/Home/Login';
import Register from '@/views/Home/Register';
import Home from '@/views/Home/Home';
import Information from '@/views/Home/Information';
import ServiceAqts from '@/views/Home/Service/aqts';
import ServiceZxym from '@/views/Home/Service/zxym';
import ServiceYjxy from '@/views/Home/Service/yjxy';
import ServiceBak from '@/views/Home/Service/bak';
import ServiceThreaten from '@/views/Home/Service/threaten';
import Talent from '@/views/Home/Talent';
import TalentInfo from '@/views/Home/Talent/info';
import Recruit from '@/views/Home/Recruit';
import Company from '@/views/Home/Company';
import CompanyInfo from '@/views/Home/Company/info';
import RecordCompany from '@/views/Home/RecordCompany';
import Work from '@/views/Home/Work';
import Supermarket from '@/views/Home/Supermarket';
import SupermarketProduct from '@/views/Home/Supermarket/product';
import Course from '@/views/Home/Course';
import CourseUser from '@/views/Home/Course/user';
import CourseDetail from '@/views/Home/Course/detail';
import ActivitySkill from '@/views/Home/Activity/skill';
import ActivityAqnh  from '@/views/Home/Activity/aqnh';
import ActivityCsaq  from '@/views/Home/Activity/csaq';

/* management */
import ManagementCourse from '@/views/Management/Course';
import ManagementService from '@/views/Management/Service';
import ManagementSupermarket from '@/views/Management/Supermarket';
import ManagementProgram from '@/views/Management/Program';
import ManagementRole from '@/views/Management/Role';
import ManagementSafePortrait from '@/views/Management/SafePortrait';

class Routes extends Component{
  requireAuth=(component)=>{
    const username = localStorage.getItem('userInfo');
    if(!username){
      return <Redirect to='/login' />;
    }else{   
      return component;
    }
  }

  render(){
    return(
      <Switch>
        <Route exact path="/login" component={Login} />
        <Route exact path="/register" component={Register} />
        <Route exact path="/" component={Home} />
        <Route exact path="/information" component={Information} />
        <Route exact path="/service/aqts" component={() => this.requireAuth(<ServiceAqts />)} />
        <Route exact path="/service/zxym" component={ServiceZxym} />
        <Route exact path="/service/yjxy" component={ServiceYjxy} />
        <Route exact path="/service/bak" component={ServiceBak} />
        <Route exact path="/service/threaten" component={ServiceThreaten} />
        <Route exact path="/talent" component={Talent} />
        <Route exact path="/talent/:id" component={TalentInfo} />
        <Route exact path="/recruit" component={Recruit} />
        <Route exact path="/company" component={Company} />
        <Route exact path="/company/:id" component={CompanyInfo} />
        <Route exact path="/recordCompany" component={RecordCompany} />
        <Route exact path="/work/:id" component={Work} />
        <Route exact path="/supermarket" component={Supermarket} />
        <Route exact path="/supermarket/:id" component={SupermarketProduct} />
        <Route exact path="/course" component={Course} />
        <Route exact path="/course/user/:id" component={CourseUser} />
        <Route exact path="/course/detail/:id" component={CourseDetail} />
        <Route exact path="/activity/skill" component={ActivitySkill} />
        <Route exact path="/activity/aqnh" component={ActivityAqnh} />
        <Route exact path="/activity/csaq" component={ActivityCsaq} />

        <Route exact path="/management/course" component={() => this.requireAuth(<ManagementCourse />)} />
        <Route exact path="/management/service" component={() => this.requireAuth(<ManagementService />)} />
        <Route exact path="/management/supermarket" component={() => this.requireAuth(<ManagementSupermarket />)} />        
        <Route exact path="/management/program" component={() => this.requireAuth(<ManagementProgram />)} />                
        <Route exact path="/management/role" component={() => this.requireAuth(<ManagementRole />)} />                           
        <Route exact path="/management/safePortrait" component={() => this.requireAuth(<ManagementSafePortrait />)} />        

        <Redirect to='/' />
      </Switch>
    )
  }
}

export default withRouter(Routes);